package com.cy.store.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        //通过session，来判断用户是否登录过
        Object uid = request.getSession().getAttribute("uid");
        //如果uid为空，则跳转到登录页面
        if(uid==null){
            response.sendRedirect("/web/login.html");
            //结束后的调用，false代表拦截
            return false;
        }
        //true代表放行
        return true;
    }
}
